<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title></title>
    <div>
        <h3>常量</h3>
        <p>摄像头支持的分辨率(supportedImageResolutions): <span id="supportedImageResolutions"></span></p>
    </div>
    <div>
        <h3>方法</h3>
        <p onclick="shareSystem()">通过系统组件分享</p>
        <p onclick="shareAction()">登录授权分享认证</p>
        <p onclick="shareaction(shares[0])">发送分享</p>
        <p onclick="shareWeixinMessage()">分享链接到微信朋友圈</p>
    </div>
    <script type="text/javascript">
        var shares=null;
        // 监听plusready事件
        document.addEventListener( "plusready", function(){
            // 扩展API加载完毕，现在可以正常调用扩展API
            plus.share.getServices( function(s){
                shares = s;
            }, function(e){
                console.log("获取分享服务列表失败："+e.message);
            } );
        }, false );

        function shareAction(){
            var s = shares[0];
            if ( !s.authenticated ) {
                s.authorize(function(){
                    console.log("认证完成");
                }, function(){
                    console.log("未进行认证");
                });
            }
        }


        // 通过系统组件分享
        function shareSystem(){
            plus.share.sendWithSystem({content:'分享内容',href:'http://www.dcloud.io/'}, function(){
                console.log('分享成功');
            }, function(e){
                console.log('分享失败：'+JSON.stringify(e));
            });
        }

        /**
         * 分享操作
         * @param {plus.share.ShareService} s
         */
        function shareaction(s) {
            if ( !s ) {
                return;
            }
            if ( s.authenticated ) {
                shareMessage( s );
            } else {
                s.authorize( shareMessage, function(e){
                    alert( "未进行认证" );
                });
            }
        }
        /**
         * 发送分享消息
         * @param {plus.share.ShareService} s
         */
        function shareMessage(s){
            s.send( {content:"Hello"}, function(){
                alert( "分享成功！" );
            }, function(e){
                alert( "分享失败："+e.message );
            } );
        }


        // -------------------------分享链接到朋友圈-------------------------
        var shares=null,sharewx=null;
        // 监听plusready事件
        document.addEventListener( "plusready", function(){
            // 扩展API加载完毕，现在可以正常调用扩展API
            plus.share.getServices( function(s){
                shares = s;
                for(var i in s){
                    if('weixin'==s[i].id){
                        sharewx=s[i];
                    }
                }
            }, function(e){
                alert( "获取分享服务列表失败："+e.message );
            } );
        }, false );
        function shareWeixinMessage(){
            sharewx.send( {content:"DCloud HBuilder-做最好的HTML5开发工具",href:"http://www.dcloud.io/",extra:{scene:"WXSceneTimeline"}}, function(){
                alert( "分享成功！" );
            }, function(e){
                alert( "分享失败："+e.message );
            });
        }
    </script>
</head>
<body>

</body>
</html>